package com.share.config.tsign.config;

import com.share.config.tsign.hz.constant.ConfigConstant;
import com.share.config.tsign.hz.core.*;
import com.share.config.tsign.hz.exception.DefineException;
import com.timevale.esign.sdk.tech.v3.client.ServiceClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EQianConfig {
    private static ServiceClient SERVICE_CLIENT;

    static {
        try {
            if (SERVICE_CLIENT == null) {
                ClientHelper.registClient(); //1、注册客户端，全局使用，只需注册一次
            }

            //2、获取已初始化的客户端，以便后续正常调用SDK提供的各种服务，全局使用，只需获取一次
            SERVICE_CLIENT = ClientHelper.getServiceClient(ConfigConstant.PROJECT_ID);
        } catch (DefineException e) {
            e.getE().printStackTrace();
        }
    }

    @Bean
    public AccountHelper accountHelper() {
        return new AccountHelper(SERVICE_CLIENT);
    }

    @Bean
    public SignHelper signHelper() {
        return new SignHelper(SERVICE_CLIENT);
    }

    @Bean
    public VerifyPDFHelper verifyPDFHelper() {
        return new VerifyPDFHelper(SERVICE_CLIENT);
    }

    @Bean
    public SealHelper sealHelper() {
        return new SealHelper(SERVICE_CLIENT);
    }
}
